Skip to content

Fix flaky specs: create_spec.rb[1:12:3:2:1] and switch_types_spec.rb[1:1:2] - #23784

Closed
akabiru with Copilot wants to merge 2 commits into
devfrom
copilot/hocuspocus-add-provider-server-wire-protocol-integ
Closed

Fix flaky specs: create_spec.rb[1:12:3:2:1] and switch_types_spec.rb[1:1:2]#23784
akabiru with Copilot wants to merge 2 commits into
devfrom
copilot/hocuspocus-add-provider-server-wire-protocol-integ

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Ticket

What are you trying to accomplish?

Fix two flaky CI feature specs first seen on PR #23755. Both failures are timing/race conditions rooted in missing synchronisation after async UI transitions.

What approach did you choose and why?

switch_types_spec.rb[1:1:2] — remove redundant openSelectField

After req_text_field.expect_active!, the required CF is in Angular edit mode. type_field.activate! fires one click that concurrently triggers Angular's click-outside close on the required CF and opens the type field's editor. The immediately-following openSelectField clicked .ng-input input and called wait_for_network_idle while Angular was still settling both transitions — landing the dropdown in an indeterminate state for set_value.

Fix: remove type_field.openSelectField. set_valueselect_autocompletesearch_autocomplete already calls ng_click_autocompleter only when the dropdown is closed, so the extra call was both redundant and the source of the race.

-      type_field.activate!
-      type_field.openSelectField
-      type_field.set_value type_task.name
+      type_field.activate!
+      type_field.set_value type_task.name

create_spec.rb[1:12:3:2:1] — add explicit Turbo step synchronisation

The before block navigates a 3-step Turbo Drive wizard. Each click_on "Continue" triggers a form POST the server answers with a 422 re-render; Turbo fires turbo:render, not turbo:load. The only previous synchronisation was the implicit Capybara element-level wait in fill_in — enough to find the target field, but not enough to guarantee the full step (including the default_value: "Default value" pre-populated on custom_field_with_default_value) had settled in the DOM. When "Complete" was submitted before the default was stable, creation failed validation and wait_for_turbo timed out.

Fix: add expect(page).to have_text("2 of") / have_text("3 of") waits after each click_on "Continue". The step-progress indicator is rendered by the wizard footer only after Turbo has fully committed the new step's HTML, making it a reliable full-step synchronisation point — the same pattern already used in the sibling test at lines 365–370.

+        expect(page).to have_text("2 of") # rubocop:disable RSpec/ExpectInHook
         fill_in "Name", with: "Foo bar"
         click_on "Continue"

+        expect(page).to have_text("3 of") # rubocop:disable RSpec/ExpectInHook
         fill_in "Required Foo", with: "Required value"

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

…step synchronisation

- switch_types_spec.rb[1:1:2]: Remove redundant type_field.openSelectField between
  activate! and set_value. The set_value path (via select_autocomplete/search_autocomplete)
  already opens the dropdown if closed, making openSelectField superfluous. The extra
  click introduced a race condition while Angular was concurrently closing the required
  CF and opening the type field.

- create_spec.rb[1:12:3:2:1]: Add explicit have_text('2 of') / have_text('3 of') waits
  after each click_on 'Continue' in the before block. The Turbo Drive 422 re-renders fire
  turbo:render (not turbo:load), so the previous implicit fill_in wait only guaranteed
  the target field was visible but not that the entire step (including pre-populated
  default values) had fully settled.
Copilot AI changed the title [WIP] Add provider/server wire-protocol integration test with CI version-skew guard Fix flaky specs: create_spec.rb[1:12:3:2:1] and switch_types_spec.rb[1:1:2] Jun 16, 2026
@akabiru akabiru added the flaky-spec Addresses a Flaky Spec label Jun 16, 2026
@akabiru

akabiru commented Jun 16, 2026

Copy link
Copy Markdown
Member

cc @mrmir - not too bad 😏

Comment on lines +395 to +396
# Step 2: Fill in project details; wait to ensure Turbo has fully rendered step 2
expect(page).to have_text("2 of") # rubocop:disable RSpec/ExpectInHook

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the right strategy for dealing with timing issues.. my only issue is the actual expectation. Can we not scope the text to a particular element or region..

Suggested change
# Step 2: Fill in project details; wait to ensure Turbo has fully rendered step 2
expect(page).to have_text("2 of") # rubocop:disable RSpec/ExpectInHook
expect(page).to have_role(:progressbar, text: "2 of") # rubocop:disable RSpec/ExpectInHook

or (if using a <progress> element itself):

Suggested change
# Step 2: Fill in project details; wait to ensure Turbo has fully rendered step 2
expect(page).to have_text("2 of") # rubocop:disable RSpec/ExpectInHook
expect(page).to have_element(:progress, value: "2") # rubocop:disable RSpec/ExpectInHook


# Now switch back to a type without the required CF
type_field.activate!
type_field.openSelectField

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not fix the issue. The problem is a race condition in the production code where the schema is expected to be there, but sometimes isn't, on the required custom field.

There is an attempted fix in the form of a PR but I wanted to dig deeper if time permits to find out if the schema access can be safeguarded instead of attempting to address the issue on accessing the schema. But my proposal might already be good enough for now.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces CI flakiness in two feature specs by removing a race-prone extra interaction in an Angular edit field flow and by adding explicit synchronization points between Turbo wizard steps in the project creation flow.

Changes:

  • Remove a redundant openSelectField call when switching the work package type in the table spec to avoid competing async UI transitions.
  • Add explicit step-progress assertions after each “Continue” click in the project creation wizard to ensure the next Turbo-rendered step is fully committed before interacting with fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
spec/features/work_packages/table/switch_types_spec.rb Removes a redundant select-opening call to avoid an Angular timing race during type switching.
spec/features/projects/create_spec.rb Adds explicit wizard-step synchronization after Turbo transitions to stabilize subsequent field interactions.


# Step 2: Fill in project details
# Step 2: Fill in project details; wait to ensure Turbo has fully rendered step 2
expect(page).to have_text("2 of") # rubocop:disable RSpec/ExpectInHook

# Step 3: Fill in required custom field
# Step 3: Fill in required custom field; wait to ensure Turbo has fully rendered step 3
expect(page).to have_text("3 of") # rubocop:disable RSpec/ExpectInHook
@akabiru

akabiru commented Jul 29, 2026

Copy link
Copy Markdown
Member

I've not be able to follow up on this, I'll close it.

@akabiru akabiru closed this Jul 29, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

flaky-spec Addresses a Flaky Spec

Development

Successfully merging this pull request may close these issues.

5 participants